/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.nodes.layer;

import com.android1.amarena2d.annotations.Incomplete;
import com.android1.amarena2d.engine.AmarenaCamera;
import com.android1.amarena2d.nodes.sprites.Sprite;
import com.android1.amarena2d.texture.ManagedTexture;
import com.android1.amarena2d.texture.RepeatingTexturedMesh;
import com.badlogic.gdx.math.Vector2;

@Incomplete
//todo
public class FastScrollingBackground extends Sprite {

    protected float scrollX;
    protected float scrollY;

    protected float scrollScaleX;
    protected float scrollScaleY;

    protected boolean repeatX;
    protected boolean repeatY;
    protected AmarenaCamera camera;


    protected final Vector2 posOffset = new Vector2();

    public FastScrollingBackground(ManagedTexture managedTexture) {
        this(new RepeatingTexturedMesh(managedTexture));
    }

    public FastScrollingBackground(String texturePath) {
        this(engine.getTextureManager().getTexture(texturePath));
    }

    public FastScrollingBackground(RepeatingTexturedMesh texturedMesh) {
        super(texturedMesh);
    }


    @Override
    public void init() {
        camera = engine.getCamera();
        final ManagedTexture managedTexture = texturedMesh.getManagedTexture();
        managedTexture.init();


        final float camMinX = camera.getX() - camera.getWidth() / 2;
        final float camMaxX = camera.getX() + camera.getWidth() / 2;

        final float times = camera.getWidth() / managedTexture.getWidth();
        RepeatingTexturedMesh repeatingTexturedMesh = (RepeatingTexturedMesh) getTexturedMesh();
        repeatingTexturedMesh.setRepeatXValue(times);
        repeatingTexturedMesh.setWidth(managedTexture.getWidth() * times * 2);
        super.init();
    }


    public float getScrollX() {
        return scrollX;
    }

    public void setScrollX(float scrollX) {
        this.scrollX = scrollX;

    }

    public float getScrollY() {
        return scrollY;
    }

    public void setScrollY(float scrollY) {
        this.scrollY = scrollY;
    }
}